<template>
  <div>
    <home-category :data='Alldata' :rightProvince='rightProvince' :rightschooltype='rightschooltype'></home-category>
    <home-customized class="customized" :schooltypeNumber='schooltypeNumber'></home-customized>
    <center-screen :data='Alldata' :province='schooltypeNumber.title' :rightschooltype='rightschooltype' @getDataReset='handledataReset'></center-screen>
    <home-rose :subjectType='subjectType' @getSchoolType="getRightSchoolType"></home-rose>
    <home-radar :schoollevel='schoollevel'></home-radar>
    <china-map @getProvince="getRightProvince" class="map"></china-map>
  </div>
</template>

<script>
import ChinaMap from './components/chinaMap'
import HomeCategory from './components/category'
import HomeCustomized from './components/Customized'
import CenterScreen from './components/center'
import HomeRose from './components/Rose'
import HomeRadar from './components/radar'
import axios from 'axios'
export default {
  name: 'dataScreen',
  components: {
    ChinaMap,
    HomeCategory,
    HomeCustomized,
    CenterScreen,
    HomeRose,
    HomeRadar
  },
  data () {
    return {
      Alldata: [],
      province: [],
      schooltype: [],
      rightProvince: '',
      rightschooltype: '',
      schooltypeNumber: {
        A: 36,
        B: 6,
        subject: 98,
        title: ''
      },
      schoollevel: {
        top: 0, // 985
        middle: 0, // 211
        last: 0 // 双非
      },
      subjectType: {
        PoliticsAndlaw: 0, // 政法
        Agriculture: 0, // 农业
        normalschool: 0, // 师范
        military: 0, // 军事
        Forestry: 0, // 林业
        Sports: 0, // 体育
        Art: 0, // 艺术
        comprehensive: 0, // 综合
        nation: 0, // 民族
        FinanceAndEconomics: 0, // 财经
        medicine: 0, // 医药
        EngineeringCourse: 0, // 工科
        language: 0, // 语言
        others: 0, // 其他
        title: ''
      }
    }
  },
  methods: {
    getHomeInfo () {
      axios.get(' http://127.0.0.1:5000/')
        .then(this.getHomeInfoSucc)
      axios.get(' http://127.0.0.1:5000/province')
        .then(this.getprovince)
      axios.get(' http://127.0.0.1:5000/schooltype')
        .then(this.getschooltype)
    },
    getHomeInfoSucc (res) {
      this.schooltypeNumber.A = 0
      this.schooltypeNumber.B = 0
      this.schooltypeNumber.subject = 0
      // 格式化subjectType表
      this.subjectType.PoliticsAndlaw = 0
      this.subjectType.Agriculture = 0
      this.subjectType.normalschool = 0
      this.subjectType.military = 0
      this.subjectType.Forestry = 0
      this.subjectType.Sports = 0
      this.subjectType.Art = 0
      this.subjectType.comprehensive = 0
      this.subjectType.nation = 0
      this.subjectType.FinanceAndEconomics = 0
      this.subjectType.medicine = 0
      this.subjectType.EngineeringCourse = 0
      this.subjectType.language = 0
      this.subjectType.others = 0

      this.schoollevel.top = 0
      this.schoollevel.middle = 0
      this.schoollevel.last = 0

      if (!this.rightProvince) {
        this.Alldata = res.data
      } else {
        res.data.forEach(item => {
          if (item.province === this.rightProvince) {
            this.Alldata.push(item)
          }
        })
      }
      console.log(this.Alldata)
      this.Alldata.forEach(item => {
        if (item.dual_class_name === 'A类') {
          this.schooltypeNumber.A++
        } else if (item.dual_class_name === 'B类') {
          this.schooltypeNumber.B++
        } else {
          this.schooltypeNumber.subject++
        }
        // subjectType
        if (item.school_type === '政法') {
          this.subjectType.PoliticsAndlaw++
        } else if (item.school_type === '农业') {
          this.subjectType.Agriculture++
        } else if (item.school_type === '师范') {
          this.subjectType.normalschool++
        } else if (item.school_type === '军事') {
          this.subjectType.military++
        } else if (item.school_type === '林业') {
          this.subjectType.Forestry++
        } else if (item.school_type === '体育') {
          this.subjectType.Sports++
        } else if (item.school_type === '艺术') {
          this.subjectType.Art++
        } else if (item.school_type === '综合') {
          this.subjectType.comprehensive++
        } else if (item.school_type === '民族') {
          this.subjectType.nation++
        } else if (item.school_type === '财经') {
          this.subjectType.FinanceAndEconomics++
        } else if (item.school_type === '医药') {
          this.subjectType.medicine++
        } else if (item.school_type === '工科') {
          this.subjectType.EngineeringCourse++
        } else if (item.school_type === '语言') {
          this.subjectType.language++
        } else {
          this.subjectType.others++
        }

        if (item.school_title === '985') {
          this.schoollevel.top++
        } else if (item.school_title === '211') {
          this.schoollevel.middle++
        } else {
          this.schoollevel.last++
        }
      })

      this.subjectType.title = this.rightProvince ? this.rightProvince : '全国总览'
      this.schooltypeNumber.title = this.rightProvince ? this.rightProvince : '全国总览'
      console.log(this.schooltypeNumber)
      console.log(this.subjectType)
    },
    getprovince (res) {
      this.province = res.data
    },
    getschooltype (res) {
      this.schooltype = res.data
    },
    getRightProvince (item) {
      this.rightProvince = item
      console.log(this.rightProvince)
    },
    getRightSchoolType (res) {
      this.rightschooltype = res
      console.log(this.rightschooltype)
    },
    handledataReset () {
      this.rightProvince = ''
      this.rightschooltype = ''
      this.Alldata = []
      this.getHomeInfo()
    }
  },
  watch: {
    rightProvince () {
      this.Alldata = []
      this.getHomeInfo()
    }
  },
  mounted () {
    this.rightschooltype = ''
    this.getHomeInfo()
  }
}
</script>

<style scoped>
</style>>
